package com.example.qq.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.apkfuns.logutils.LogUtils;
import com.example.qq.R;
import com.example.qq.Vm.MsgVm;
import com.example.qq.adpter.DividerItemDecoration;
import com.example.qq.adpter.MsgAdatper;
import com.example.qq.databinding.FragmentFirstBinding;

public class FirstFragment extends Fragment {
    FragmentFirstBinding mBinding;
    MsgVm mMsgVm;

    public FirstFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_first, container, false);
        mMsgVm = new ViewModelProvider((ViewModelStoreOwner) getActivity(),
                ViewModelProvider.AndroidViewModelFactory.getInstance(getActivity().getApplication()))
                .get(MsgVm.class);
        mMsgVm.init();
        //设置设配器
        mBinding.rv.addItemDecoration(new DividerItemDecoration(getActivity()
                ,DividerItemDecoration.VERTICAL_LIST,true,true));
        mBinding.rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        mBinding.rv.setAdapter(new MsgAdatper(getActivity(), mMsgVm.getMsgList()));
        return mBinding.getRoot();
    }

    @Override
    public void onResume() {
        LogUtils.e("hello");
        super.onResume();
    }
}